//
//  Vibrate.swift
//  Social
//
//  Created by 李响 on 2019/5/30.
//  Copyright © 2019 shengsheng. All rights reserved.
//

import Foundation

/// 震动
///
/// - light: 轻度
/// - medium: 中度
/// - heavy: 重度
/// - select: 选择
public enum Vibrate: Int {
    case light
    case medium
    case heavy
    case select
}

extension Vibrate {
    
    public func play() {
        switch self {
        case .light, .medium, .heavy:
            guard let style = UIImpactFeedbackGenerator.FeedbackStyle(rawValue: rawValue) else {
                return
            }
            let generator = UIImpactFeedbackGenerator(style: style)
            generator.prepare()
            generator.impactOccurred()
            
        case .select:
            let generator = UISelectionFeedbackGenerator()
            generator.prepare()
            generator.selectionChanged()
        }
    }
}
